#include "fate.h"

#include <QDebug>

Fate::Fate(QWidget *parent)
    : QDialog(parent)
{
//      读取数据
    QSettings openFile("usrInformation.ini", QSettings::IniFormat);
    openFile.setIniCodec(QTextCodec::codecForName("UTF-8"));
    QString lastTime = openFile.value("usr/lastTime").toString();
    randomNum_1 = openFile.value("usr/randomNum_1").toInt();
    randomNum_2 = openFile.value("usr/randomNum_2").toInt();

    setWindowFlag(Qt::FramelessWindowHint);
    setStyleSheet(tr("Fate{border-image:url(:img/color/1_%1.jpg)}").arg(randomNum_2));
    setFixedSize(276, 476);

    list << "大笑" << "忘记" << "学习" << "运动" << "谈恋爱" << "游戏" << "求知" << "大吃大喝" << "选择" << "晒太阳"
         << "听风" << "整理房间" << "放假" << "问问题" << "找灵感" << "海誓山盟" << "坚持" << "赞赏他人" << "鼓励" << "帮助"
         << "释放" << "打酱油" << "中奖" << "跳出条框" << "痴迷" << "发呆" << "破除执念" << "快意飞马" << "温柔" << "表里如一"
         << "早起" << "早睡" << "仰望星空" << "逛街" << "下馆子" << "出门" << "戒色" << "告别" << "认识自己" << "安慰"
         << "露怯" << "刷脸" << "打卡" << "示弱" << "大度" << "宽恕" << "期待" << "等待" << "看书" << "聊聊天"
         << "交朋友" << "洗衣服" << "做饭" << "葛优躺" << "鬼畜" << "追番" << "追剧" << "买东西" << "还钱" << "骑车"
         << "赖床" << "舍弃" << "转身" << "权衡" << "挑战" << "斗图" << "呆萌" << "放慢节奏" << "聚会" << "低调"
         << "抱一抱" << "睡午觉" << "开阔眼界" << "迈开腿" << "心动" << "敲代码" << "涨知识" << "缓和" << "冷静" << "装深沉"
         << "吃火锅" << "思考人身" << "牵一只蜗牛去散步" << "看海" << "放声大歌" << "请客" << "掏空身体" << "吹吹冷风" << "定目标" << "回家"
         << "洗洗睡" << "狂拽" << "乘胜追击" << "吃辣条" << "默默忧伤" << "聚人心" << "回首" << "涨工资" << "直言不讳" << "据理力争"
         << "不拘小节" << "生子" << "重新开始" << "浪漫一场" << "诗禅" << "打坐" << "静心" << "努力" << "谨慎" << "念旧"
         << "开黑" << "梳梳头" << "吃水果" << "小跑" << "写文章" << "白日梦" << "省钱" << "悲伤" << "打滚" << "找油泥怪聊天"
         << "郊游" << "煲电话" << "洗头" << "发说说" << "静心独处" << "与人为善" << "关掉手机" << "什么也不干" << "劳累" << "洗衣服"
         << "健康" << "喝牛奶" << "想桃子" << "点赞" << "下棋" << "抢红包" << "陪陪家人" << "喝开水" << "去别的学校" << "登高"
         << "拍照" << "回忆过往" << "记日记" << "听歌" << "玩玩具" << "打扫房间" << "听话" << "有主见" << "去书店" << "借书"
         << "放松身心" << "遵从内心" << "看电影" << "撒娇" << "小哭一场" << "找油泥怪对线" << "请油泥怪吃饭" << "刷题" << "困惑" << "批判"
         << "数星星" << "白云悠悠" << "快乐一天" << "吃烧烤" << "原谅" << "幡然醒悟" << "发现生活" << "改变自己" << "喜欢" << "画画"
         << "吹牛" << "守诺言" << "幸运" << "开光" << "找npy" << "宅" << "栽种" << "钓鱼" << "安床" << "出行"
         << "祝福" << "有礼貌" << "点外卖" << "吃食堂" << "关注油泥怪" << "探宝" << "挖掘" << "纳财" << "张灯结彩" << "庆祝"
         << "哀悼" << "简约" << "调侃" << "开玩笑" << "加油" << "我编不出来了" << "哈哈哈哈" << "你以为呢" << "四处逛逛" << "健身"
         << "果断" << "雄心" << "昂首挺胸" << "取舍" << "饿" << "报名" << "取快递" << "倒垃圾" << "穿新衣" << "心平气和"
         << "奥利给" << "欣赏" << "走走停停" << "看风景" << "相遇" << "心直口快" << "扬眉吐气" << "心血来潮" << "立愿" << "息事宁人"
         << "眉开眼笑" << "舒展身体" << "强大内心" << "无所畏惧" << "跑跑跳跳" << "做梦" << "慎思笃行" << "收敛" << "喜新厌旧" << "走神"
         << "找你" << "打酱油" << "走心" << "磨蹭" << "享受孤独" << "展魅力" << "谈笑风生" << "谈钱" << "倾听" << "全心全意"
         << "矫情" << "毁三观" << "悠然自得" << "拥抱" << "将心比心" << "向前一步" << "冥想" << "谈人生" << "积攒能量" << "拥有";

//      天数变化就
    QDateTime currentTime = QDateTime::currentDateTime();
    //qDebug() << datetime.toString("hh:mm") << datetime.toString("dd");
    if(currentTime.toString("yyyy:MM:dd") != lastTime)
    {
        qsrand(quint32(time(nullptr)));
        randomNum_1 = qrand() % 250;
        randomNum_2 = qrand() % 9 + 1;
        QSettings saveFile("usrInformation.ini", QSettings::IniFormat);
        saveFile.setIniCodec(QTextCodec::codecForName("UTF-8"));
        saveFile.setValue("usr/lastTime", currentTime.toString("yyyy:MM:dd"));
        saveFile.setValue("usr/randomNum_1", randomNum_1);
        saveFile.setValue("usr/randomNum_2", randomNum_2);
    }

    label_1 = new QLabel(this);
    label_1->setText(tr("宜  %1").arg(list[randomNum_1]));
    label_1->setStyleSheet("QLabel{font-size:20px; font-family:'楷体'; color:white}");
    label_1->move(40, 320);

    btnClose = new QPushButton(this);
    btnClose->resize(30, 30);
    btnClose->move(236, 10);
    btnClose->setStyleSheet("QPushButton{border-image:url(:img/close.png)}"
                            "QPushButton:hover{border-image:url(:img/close-hover.png)}");
    connect(btnClose, &QPushButton::clicked, this, &Fate::closeWindow);
}
Fate::~Fate()
{
}

/**
 * 基本设置
 */

void Fate::closeWindow()
{
    reject();
}
void Fate::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        m_move = true;
        m_startPoint = event->globalPos();
        m_windowPoint = this->frameGeometry().topLeft();
    }
}
void Fate::mouseMoveEvent(QMouseEvent *event)
{
    if (m_move)
    {
        QPoint relativePos = event->globalPos() - m_startPoint;
        this->move(m_windowPoint + relativePos);
    }
}
void Fate::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        m_move = false;
    }
}
